package com.liuqi.knet.remoting;

/**
 * 通道缓存器, 由ThreadLocal进行缓存.
 *
 * @author liuqi
 * @date 2024/12/17 15:51
 **/
public final class ChannelContext {

    private final static ThreadLocal<Channel> channels = new InheritableThreadLocal<Channel>();

    /**
     * 获取当前线程中的 Channel
     *
     * @return
     */
    public final static Channel getCurrentChannel() {
        return channels.get();
    }

    /**
     * 为当前线程设置通道
     *
     * @param channel
     */
    public final void setCurrentChannel(Channel channel) {
        channels.set(channel);
    }

    /**
     * 移除当前线程中的缓存
     */
    public final void removeCurrentChannel() {
        channels.remove();
    }

}
